﻿using Com.JunCaiSoft.API.WXWork.Dto;
using Com.JunCaiSoft.AutoMapper;
using Com.JunCaiSoft.Common.AssistClass;
using Com.JunCaiSoft.Common.ExchangeData;
using Com.JunCaiSoft.NoticeSystem.Entity;
using Com.JunCaiSoft.NoticeSystem.Model.Notice;
using Com.JunCaiSoft.Permission.Entity;
using Com.JunCaiSoft.Permission.Model;
using Microsoft.AspNetCore.Builder;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Com.JunCaiSoft.NoticeSystem
{
    public static class NoticeSystemAutoMapperConfigure
    {
        public static void CreateNoticeSystemMapper(IApplicationBuilder app)
        {
            var creator = app.UseAutoMapper();

            #region 通知日志
            creator.CreateMap<Notice, NoticeView>()
                .ForMember(dest => dest.ReSendNotice,opt => opt.Ignore())
                .ForMember(dest => dest.Targets,opt => opt.Ignore())
                .ForMember(dest => dest.Content, opt => opt.MapFrom(src => JsonConvert.DeserializeObject<TextCard>(src.Content)))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")));
            creator.CreateMap<NoticeView, Notice>()
                .ForMember(dest => dest.Content, opt => opt.MapFrom(src => JsonConvert.SerializeObject(src.Content)))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => DateTime.Parse(src.CreateTime)));
            #endregion

        }
    }
}
